home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 1996 #6 / Amiga Plus CD - 1996 - No. 06.iso / pd / programmierung / proasm / routines / numbers.mac < prev    next >
Text File  |  1994-04-01  |  3KB  |  200 lines

  1.  
  2. ;---;  numbers.r  ;------------------------------------------------------------
  3. *
  4. *    ****    NUMBER IN & OUTPUT ROUTINES    ****
  5. *
  6. *    Author        Stefan Walter
  7. *    Version        1.01
  8. *    Last Revision    25.06.93
  9. *    Identifier    nio_defined
  10. *    Prefix        nio_    (number in out)
  11. *                 ¯      ¯  ¯
  12. *    Macros        GetHexNumber_, GetDecNumber_
  13. *
  14. ;------------------------------------------------------------------------------
  15.  
  16. ;------------------
  17.     ifnd    nio_defined
  18. nio_defined    =1
  19.  
  20. ;------------------
  21. nio_oldbase    equ __base
  22.     base    nio_base
  23. nio_base:
  24.  
  25. ;------------------
  26.  
  27. ;------------------------------------------------------------------------------
  28. *
  29. * GetHexNumber_        Try to get a hexadecimal number. "$" and C-style "0x"
  30. *            introducers supported
  31. *
  32. * INPUT:    a0    String to interprete.
  33. *
  34. * RESULT:    d0    Result.
  35. *        d1    0 if error, -1 if okay.
  36. *        ccr    On d1.
  37. *
  38. ;------------------------------------------------------------------------------
  39.  
  40. ;------------------
  41. ; Macro
  42. ;
  43. GetHexNumber_    macro
  44.     ifd    nio_GetHexNumber
  45.         bsr    nio_GetHexNumber
  46.     else
  47.         pea    .nio_end1(pc)
  48.  
  49. ;------------------
  50. ; Remove spaces first
  51. ;
  52. nio_GetHexNumber    =    *
  53.     move.l    d2,-(sp)
  54.  
  55. .sloop:    cmp.b    #" ",(a0)+
  56.     beq.s    .sloop
  57.     tst.b    -(a0)
  58.     beq.s    .error
  59.     cmp.b    #$a,(a0)
  60.     beq.s    .error
  61.     cmp.b    #"0",(a0)+
  62.     bne.s    .dol
  63.     move.b    (a0)+,d0
  64.     and.b    #$df,d0
  65.     cmp.b    #"X",d0
  66.     beq.s    .nowcomesnumber
  67.     subq.l    #1,a0
  68. .dol:    cmp.b    #"$",-(a0)
  69.     bne.s    .nowcomesnumber
  70.     addq.l    #1,a0
  71.  
  72. .nowcomesnumber:
  73.     moveq    #0,d0
  74. .numberloop:
  75.     move.b    (a0)+,d2
  76.     move.b    d2,d1
  77.     beq.s    .done
  78.     cmp.b    #" ",d2
  79.     beq.s    .done
  80.     cmp.b    #$a,d2
  81.     beq.s    .done
  82.     sub.b    #"0",d2
  83.     blt.s    .error
  84.     cmp.b    #10,d2
  85.     blt.s    .okay
  86.     move.b    d1,d2
  87.     and.b    #$df,d2
  88.     sub.b    #"A",d2
  89.     blt.s    .error
  90.     cmp.b    #5,d2
  91.     bhi.s    .error
  92.     add.b    #10,d2
  93.  
  94. .okay:    lsl.l    #4,d0
  95.     or.b    d2,d0
  96.     bra.s    .numberloop
  97.  
  98. .error:    move.l    (sp)+,d2
  99.     moveq    #0,d1
  100.     rts
  101.  
  102. .done:    move.l    (sp)+,d2
  103.     moveq    #-1,d1
  104.     rts
  105.  
  106.  
  107. ;------------------
  108. ; End of macro.
  109. ;
  110. .nio_end1:
  111.     endif
  112.     endm
  113.  
  114. ;------------------
  115.  
  116. ;------------------------------------------------------------------------------
  117. *
  118. * GetDecNumber_        Try to get a decimal number.
  119. *
  120. * INPUT:    a0    String to interprete.
  121. *
  122. * RESULT:    d0    Result.
  123. *        d1    0 if error, -1 if okay.
  124. *        ccr    On d1.
  125. *
  126. ;------------------------------------------------------------------------------
  127.  
  128. ;------------------
  129. ; Macro
  130. ;
  131. GetDecNumber_    macro
  132.     ifd    nio_GetDecNumber
  133.         bsr    nio_GetDecNumber
  134.     else
  135.         pea    .nio_end2(pc)
  136.  
  137. ;------------------
  138. ; Remove spaces first
  139. ;
  140. nio_GetDecNumber    =    *
  141.     movem.l    d2/d3,-(sp)
  142.  
  143. .sloopd:    cmp.b    #" ",(a0)+
  144.     beq.s    .sloopd
  145.     tst.b    -(a0)
  146.     beq.s    .errord
  147.     cmp.b    #$a,(a0)
  148.     beq.s    .errord
  149.  
  150. .nowcomesnumberd:
  151.     moveq    #0,d0
  152. .numberloopd:
  153.     moveq    #0,d2
  154.     move.b    (a0)+,d2
  155.     move.b    d2,d1
  156.     beq.s    .doned
  157.     cmp.b    #" ",d2
  158.     beq.s    .doned
  159.     cmp.b    #$a,d2
  160.     beq.s    .doned
  161.  
  162.     move.l    d0,d3
  163.     lsl.l    #3,d0            ;
  164.     add.l    d3,d0            ;
  165.     add.l    d3,d0            ; d0*10
  166.     sub.b    #"0",d2
  167.     blt.s    .errord
  168.     cmp.b    #10,d2
  169.     bhs.s    .errord
  170.     add.l    d2,d0
  171.     bra.s    .numberloopd
  172.  
  173. .errord:moveq    #0,d1
  174. .exitd:    movem.l    (sp)+,d2/d3
  175.     rts
  176.  
  177. .doned:    moveq    #-1,d1
  178.     bra.s    .exitd
  179.  
  180.  
  181. ;------------------
  182. ; End of macro.
  183. ;
  184. .nio_end2:
  185.     endif
  186.     endm
  187.  
  188. ;------------------
  189.  
  190. ;--------------------------------------------------------------------
  191.  
  192. ;------------------
  193.     base    nio_oldbase
  194.  
  195. ;------------------
  196.     endif
  197.  
  198.     end
  199.  
  200.